Skip to content

OrientedTableView

Base classes

Name Children Inherits
TableView
prettyqt.widgets.tableview
Default model/view implementation of a table view.

⋔ Inheritance diagram

graph TD
  682009552["custom_widgets.OrientedTableView"]
  1288268085["widgets.TableView"]
  2313507980["widgets.TableViewMixin"]
  3836649406["widgets.AbstractItemViewMixin"]
  1259044718["widgets.AbstractScrollAreaMixin"]
  1689631995["widgets.FrameMixin"]
  829357528["widgets.WidgetMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  625385617["gui.PaintDeviceMixin"]
  2435783731["QtWidgets.QTableView"]
  3038536384["QtWidgets.QAbstractItemView"]
  1459025998["QtWidgets.QAbstractScrollArea"]
  3822057598["QtWidgets.QFrame"]
  3620195106["QtWidgets.QWidget"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  673956333["QtGui.QPaintDevice"]
  1288268085 --> 682009552
  2313507980 --> 1288268085
  3836649406 --> 2313507980
  1259044718 --> 3836649406
  1689631995 --> 1259044718
  829357528 --> 1689631995
  3227531497 --> 829357528
  2751680898 --> 3227531497
  625385617 --> 829357528
  2751680898 --> 625385617
  2751680898 --> 829357528
  2751680898 --> 1689631995
  2751680898 --> 1259044718
  2751680898 --> 3836649406
  2751680898 --> 2313507980
  2435783731 --> 1288268085
  3038536384 --> 2435783731
  1459025998 --> 3038536384
  3822057598 --> 1459025998
  3620195106 --> 3822057598
  3984060476 --> 3620195106
  37984305 --> 3984060476
  2751680898 --> 37984305
  673956333 --> 3620195106
  37984305 --> 673956333

🛈 DocStrings

Bases: TableView

TableView class with some convenience methods for oriented tables.

Source code in prettyqt/custom_widgets/orientedtableview.py
class OrientedTableView(widgets.TableView):
    """TableView class with some convenience methods for oriented tables."""

    def __init__(
        self, orientation: constants.Orientation | constants.OrientationStr, **kwargs
    ):
        super().__init__(**kwargs)
        self.orientation = constants.ORIENTATION.get_enum_value(orientation)

    @classmethod
    def setup_example(cls):
        return cls(orientation="vertical")

    def get_higher_levels(self, levels: int) -> core.ItemSelection:
        model = self.model()
        if self.is_horizontal():
            # Get the header's selected columns
            # Removes the higher levels so that only the lowest level of the header
            # affects the data table selection
            return core.ItemSelection(
                model.index(0, 0), model.index(levels - 2, model.columnCount() - 1)
            )
        return core.ItemSelection(
            model.index(0, 0), model.index(model.rowCount() - 1, levels - 2)
        )

    def set_section_span(self, row: int, column: int, count: int):
        if self.is_horizontal():
            self.setSpan(row, column, 1, count)
        else:
            self.setSpan(column, row, count, 1)

    def sectionAt(self, val: int):
        return self.columnAt(val) if self.is_horizontal() else self.rowAt(val)

    def over_header_edge(self, position: int, margin: int = 3) -> int | None:
        # Return the index of the column this x position is on the right edge of
        left = self.sectionAt(position - margin)
        right = self.sectionAt(position + margin)
        if left != right != 0:
            # We're at the left edge of the first column
            return left
        return None

    def is_horizontal(self) -> bool:
        return self.orientation == constants.HORIZONTAL

    def sectionWidth(self, val: int):
        return self.columnWidth(val) if self.is_horizontal() else self.rowHeight(val)

    def setSectionWidth(self, section: int, width: int):
        if self.is_horizontal():
            self.setColumnWidth(section, width)
        else:
            self.setRowHeight(section, width)

    def get_split_cursor(self) -> gui.Cursor:
        if self.is_horizontal():
            return gui.Cursor(constants.CursorShape.SplitHCursor)
        return gui.Cursor(constants.CursorShape.SplitVCursor)

:fa-brands-github: Show source on GitHub